(function(d) {
    var f, g = function() {},
        b = mobiscroll,
        a = b.$,
        e = b.util,
        c = e.getCoord,
        h = e.testTouch;
    b.classes.Form = function(q, r) {
        var d, n, m, k = '',
            j = a(q),
            i = this;

        function o(b) {
            var g = {},
                c = b[0],
                j = b.parent(),
                h = b.attr('data-password-toggle'),
                d = b.attr('data-icon-show') || 'eye',
                f = b.attr('data-icon-hide') || 'eye-blocked';
            if (h) {
                g.right = c.type == 'password' ? d : f;
            }
            e.addIcon(b, g);
            if (h) {
                i.tap(j.find('.mbsc-right-ic'), function() {
                    if (c.type == "text") {
                        c.type = "password";
                        a(this).addClass('mbsc-ic-' + d).removeClass('mbsc-ic-' + f);
                    } else {
                        c.type = "text";
                        a(this).removeClass('mbsc-ic-' + d).addClass('mbsc-ic-' + f);
                    }
                });
            }
        }

        function t() {
            var b = this;
            if (!a(b).hasClass('mbsc-textarea-scroll')) {
                var c = b.scrollHeight - b.offsetHeight,
                    d = b.offsetHeight + c;
                b.scrollTop = 0;
                b.style.height = d + 'px';
            }
        }

        function s(b) {
            var c, d, e;
            if (b.offsetHeight) {
                b.style.height = '';
                e = b.scrollHeight - b.offsetHeight;
                c = b.offsetHeight + (e > 0 ? e : 0);
                d = Math.round(c / 24);
                if (d > 10) {
                    b.scrollTop = c;
                    c = 240 + (c - d * 24);
                    a(b).addClass('mbsc-textarea-scroll');
                } else {
                    a(b).removeClass('mbsc-textarea-scroll');
                }
                if (c) {
                    b.style.height = c + 'px';
                }
            }
        }

        function p() {
            clearTimeout(n);
            n = setTimeout(function() {
                a('textarea.mbsc-control', j).each(function() {
                    s(this);
                });
            }, 100);
        }

        function l(a) {
            return !!(a.id && b.instances[a.id]);
        }
        b.classes.Base.call(this, q, r, true);
        i.refresh = function(g) {
            a('input,select,textarea,progress,button', j).each(function() {
                function A() {
                    a('input', r).val(p.selectedIndex != -1 ? p.options[p.selectedIndex].text : '');
                }
                var w, y, u, C, B, p = this,
                    k = a(p),
                    r = k.parent(),
                    x = k.attr('data-role'),
                    q = k.attr('type') || p.nodeName.toLowerCase();
                if (k.attr('data-enhance') != 'false' && mobiscroll.running) {
                    if (/(switch|range|segmented|stepper)/.test(x)) {
                        q = x;
                    }
                    if (k.hasClass('mbsc-control')) {
                        if (/(switch|range|progress)/.test(q) && l(p) && !g) {
                            b.instances[p.id].option({
                                theme: d.theme,
                                lang: d.lang,
                                onText: d.onText,
                                offText: d.offText,
                                stopProp: d.stopProp
                            });
                        }
                    } else {
                        if (q != 'button' && q != 'submit' && q != 'segmented') {
                            r.find('label').addClass('mbsc-label');
                            r.contents().filter(function() {
                                return this.nodeType == 3 && this.nodeValue && /\S/.test(this.nodeValue);
                            }).each(function() {
                                a('<span class="mbsc-label"></span>').insertAfter(this).append(this);
                            });
                        }
                        k.addClass('mbsc-control');
                        switch (q) {
                            case 'button':
                            case 'submit':
                                y = k.attr('data-icon');
                                k.addClass('mbsc-btn');
                                if (y) {
                                    k.prepend('<span class="mbsc-btn-ic mbsc-ic mbsc-ic-' + y + '"></span>');
                                    if (k.text() === "") {
                                        k.addClass('mbsc-btn-icon-only');
                                    }
                                }
                                break;
                            case 'switch':
                                if (!l(p)) {
                                    new b.classes.Switch(p, {
                                        theme: d.theme,
                                        lang: d.lang,
                                        rtl: d.rtl,
                                        onText: d.onText,
                                        offText: d.offText,
                                        stopProp: d.stopProp
                                    });
                                }
                                break;
                            case 'checkbox':
                                r.prepend(k).addClass('mbsc-checkbox mbsc-control-w');
                                k.after('<span class="mbsc-checkbox-box"></span>');
                                break;
                            case 'range':
                                if (!r.hasClass('mbsc-slider') && !l(p)) {
                                    new b.classes.Slider(p, {
                                        theme: d.theme,
                                        lang: d.lang,
                                        rtl: d.rtl,
                                        stopProp: d.stopProp
                                    });
                                }
                                break;
                            case 'progress':
                                if (!l(p)) {
                                    new b.classes.Progress(p, {
                                        theme: d.theme,
                                        lang: d.lang,
                                        rtl: d.rtl
                                    });
                                }
                                break;
                            case 'radio':
                                r.addClass('mbsc-radio mbsc-control-w');
                                k.after('<span class="mbsc-radio-box"><span></span></span>');
                                break;
                            case 'select':
                            case 'select-one':
                            case 'select-multiple':
                                if (k.prev().is('input.mbsc-control')) {
                                    w = k.prev();
                                } else {
                                    w = a('<input tabindex="-1" type="text" class="mbsc-control mbsc-control-ev" readonly>');
                                }
                                o(k);
                                r.addClass('mbsc-input mbsc-select mbsc-control-w');
                                k.after(w);
                                w.after('<span class="mbsc-select-ic mbsc-ic mbsc-ic-arrow-down5"></span>');
                                break;
                            case 'textarea':
                                o(k);
                                r.addClass('mbsc-input mbsc-textarea mbsc-control-w');
                                break;
                            case 'segmented':
                                var v, z;
                                if (!k.parent().hasClass('mbsc-segmented-item')) {
                                    z = a('<div class="mbsc-segmented"></div>');
                                    r.after(z);
                                    a('input[name="' + k.attr('name') + '"]', j).each(function(c, b) {
                                        v = a(b).parent().addClass('mbsc-segmented-item');
                                        a('<span class="mbsc-segmented-content">' + (a(b).attr('data-icon') ? ' <span class="mbsc-ic mbsc-ic-' + a(b).attr('data-icon') + '"></span> ' : '') + '</span>').append(v.contents()).appendTo(v);
                                        v.prepend(b);
                                        z.append(v);
                                    });
                                }
                                break;
                            case 'stepper':
                                if (!l(p)) {
                                    new b.classes.Stepper(p, {
                                        form: i
                                    });
                                }
                                break;
                            case 'hidden':
                                break;
                            default:
                                o(k);
                                r.addClass('mbsc-input mbsc-control-w');
                                break;
                        }
                    }
                    if (!k.hasClass('mbsc-control-ev')) {
                        if (/select/.test(q) && !k.hasClass('mbsc-comp')) {
                            k.on('change.mbsc-form', A);
                            A();
                        }
                        if (q == 'textarea') {
                            k.on('keydown.mbsc-form input.mbsc-form', function() {
                                clearTimeout(n);
                                n = setTimeout(function() {
                                    s(p);
                                }, 100);
                            }).on('scroll.mbsc-form', t);
                        }
                        k.addClass('mbsc-control-ev').on('touchstart.mbsc-form mousedown.mbsc-form', function(b) {
                            if (h(b, this)) {
                                C = c(b, 'X');
                                B = c(b, 'Y');
                                if (f) {
                                    f.removeClass('mbsc-active');
                                }
                                if (!p.disabled) {
                                    u = true;
                                    f = a(this);
                                    a(this).addClass('mbsc-active');
                                    m('onControlActivate', {
                                        target: this,
                                        domEvent: b
                                    });
                                }
                            }
                        }).on('touchmove.mbsc-form mousemove.mbsc-form', function(a) {
                            if (u && Math.abs(c(a, 'X') - C) > 9 || Math.abs(c(a, 'Y') - B) > 9) {
                                k.removeClass('mbsc-active');
                                m('onControlDeactivate', {
                                    target: k[0],
                                    domEvent: a
                                });
                                u = false;
                            }
                        }).on('touchend.mbsc-form touchcancel.mbsc-form mouseleave.mbsc-form mouseup.mbsc-form', function(a) {
                            if (u && a.type == 'touchend' && !p.readOnly) {
                                p.focus();
                                if (/(button|submit|checkbox|switch|radio)/.test(q)) {
                                    a.preventDefault();
                                }
                                if (!/select/.test(q)) {
                                    var b = (a.originalEvent || a).changedTouches[0],
                                        c = document.createEvent('MouseEvents');
                                    c.initMouseEvent('click', true, true, window, 1, b.screenX, b.screenY, b.clientX, b.clientY, false, false, false, false, 0, null);
                                    c.tap = true;
                                    p.dispatchEvent(c);
                                    e.preventClick();
                                }
                            }
                            if (u) {
                                setTimeout(function() {
                                    k.removeClass('mbsc-active');
                                    m('onControlDeactivate', {
                                        target: k[0],
                                        domEvent: a
                                    });
                                }, 100);
                            }
                            u = false;
                            f = null;
                        });
                    }
                }
            });
            if (!g) {
                p();
            }
        };
        i.init = function(c) {
            i._init(c);
            if (!b.themes.form[d.theme]) {
                d.theme = 'mobiscroll';
            }
            if (!j.hasClass('mbsc-form')) {
                j.on('touchstart', g).show();
                a(window).on('resize orientationchange', p);
            }
            if (k) {
                j.removeClass(k);
            }
            k = 'mbsc-form mbsc-' + d.theme + (d.baseTheme ? ' mbsc-' + d.baseTheme : '') + (d.rtl ? ' mbsc-rtl' : ' mbsc-ltr');
            j.addClass(k);
            i.refresh();
            i.trigger('onInit');
        };
        i.destroy = function() {
            j.removeClass(k).off('touchstart', g);
            a(window).off('resize orientationchange', p);
            a('.mbsc-control', j).off('.mbsc-form').removeClass('mbsc-control-ev');
            i._destroy();
            a('.mbsc-progress progress', j).mobiscroll('destroy');
            a('.mbsc-slider input', j).mobiscroll('destroy');
            a('.mbsc-stepper input', j).mobiscroll('destroy');
            a('.mbsc-switch input', j).mobiscroll('destroy');
        };
        d = i.settings;
        m = i.trigger;
        i.init(r);
    };
    b.classes.Form.prototype = {
        _hasDef: true,
        _hasTheme: true,
        _hasLang: true,
        _class: 'form',
        _defaults: {
            tap: true,
            stopProp: true,
            lang: 'en'
        }
    };
    b.themes.form.mobiscroll = {};
    b.presetShort('form', 'Form');
    b.classes.Stepper = function(n, y) {
        var o, x, B, C, l, u, P, G, A, L, N, p, j, k, g, r, K, F, e, i = this,
            f = a(n),
            t, m, z = e,
            q = y.form;

        function H(b) {
            if (b.keyCode == 32) {
                b.preventDefault();
                if (!l && !n.disabled) {
                    o = a(this).addClass('mbsc-active');
                    O(b);
                }
            }
        }

        function I(a) {
            if (l) {
                a.preventDefault();
                E(true);
            }
        }

        function J(b) {
            if (h(b, this) && !n.disabled) {
                o = a(this).addClass('mbsc-active').trigger('focus');
                if (q) {
                    q.trigger('onControlActivate', {
                        target: o[0],
                        domEvent: b
                    });
                }
                O(b);
                if (b.type === 'mousedown') {
                    a(document).on('mousemove', w).on('mouseup', v);
                }
            }
        }

        function v(b) {
            if (l) {
                b.preventDefault();
                E(true, b);
                if (b.type === 'mouseup') {
                    a(document).off('mousemove', w).off('mouseup', v);
                }
            }
        }

        function w(a) {
            if (l) {
                L = c(a, 'X');
                N = c(a, 'Y');
                P = L - K;
                G = N - F;
                if (Math.abs(P) > 7 || Math.abs(G) > 7) {
                    E();
                }
            }
        }

        function M() {
            var b;
            if (!n.disabled) {
                b = parseFloat(a(this).val());
                s(isNaN(b) ? e : b);
            }
        }

        function s(c, a, b) {
            z = e;
            if (a === d) {
                a = true;
            }
            if (b === d) {
                b = a;
            }
            if (c !== d) {
                e = Math.min(j, Math.max(Math.round(c / g) * g, k));
            } else {
                e = Math.min(j, Math.max(e + (o.hasClass('mbsc-stepper-minus') ? -g : g), k));
            }
            u = true;
            C.removeClass('mbsc-step-disabled');
            if (a) {
                f.val(e);
            }
            if (e == k) {
                B.addClass('mbsc-step-disabled');
            } else if (e == j) {
                x.addClass('mbsc-step-disabled');
            }
            if (e !== z && b) {
                f.trigger('change');
            }
        }

        function O(a) {
            if (!l) {
                l = true;
                u = false;
                K = c(a, 'X');
                F = c(a, 'Y');
                clearInterval(p);
                clearTimeout(p);
                p = setTimeout(function() {
                    s();
                    p = setInterval(function() {
                        s();
                    }, 150);
                }, 300);
            }
        }

        function E(a, b) {
            clearInterval(p);
            clearTimeout(p);
            if (!u && a) {
                s();
            }
            l = false;
            u = false;
            o.removeClass('mbsc-active');
            if (q) {
                setTimeout(function() {
                    q.trigger('onControlDeactivate', {
                        target: o[0],
                        domEvent: b
                    });
                }, 100);
            }
        }

        function D(b, c) {
            var a = f.attr(b);
            return a === d || a === '' ? c : +a;
        }
        b.classes.Base.call(this, n, y, true);
        i.getVal = function() {
            var a = parseFloat(f.val());
            a = isNaN(a) ? e : a;
            return Math.min(j, Math.max(Math.round(a / g) * g, k));
        };
        i.setVal = function(a, b, c) {
            a = parseFloat(a);
            s(isNaN(a) ? e : a, b, c);
        };
        i.init = function(b) {
            t = f.parent().hasClass('mbsc-stepper');
            m = t ? f.closest('.mbsc-stepper-cont') : f.parent();
            i._init(b);
            r = i.settings;
            k = b.min === d ? D('min', r.min) : b.min;
            j = b.max === d ? D('max', r.max) : b.max;
            g = b.step === d ? D('step', r.step) : b.step;
            A = f.attr('data-val') || r.val;
            e = Math.min(j, Math.max(Math.round(+n.value / g) * g || 0, k));
            if (!t) {
                m.addClass('mbsc-stepper-cont mbsc-control-w').append('<span class="mbsc-segmented mbsc-stepper"></span>').find('.mbsc-stepper').append('<span class="mbsc-segmented-item mbsc-stepper-control mbsc-stepper-minus ' + (e == k ? 'mbsc-step-disabled' : '') + '"  tabindex="0"><span class="mbsc-segmented-content"><span class="mbsc-ic mbsc-ic-minus"></span></span></span>').append('<span class="mbsc-segmented-item mbsc-stepper-control mbsc-stepper-plus ' + (e == j ? 'mbsc-step-disabled' : '') + '"  tabindex="0"><span class="mbsc-segmented-content"> <span class="mbsc-ic mbsc-ic-plus"></span> </span></span>').prepend(f);
            }
            B = a('.mbsc-stepper-minus', m);
            x = a('.mbsc-stepper-plus', m);
            if (!t) {
                if (A == 'left') {
                    m.addClass('mbsc-stepper-val-left');
                    f.after('<span class="mbsc-segmented-item"><span class="mbsc-segmented-content"></span></span>');
                } else if (A == 'right') {
                    m.addClass('mbsc-stepper-val-right');
                    x.after('<span class="mbsc-segmented-item"><span class="mbsc-segmented-content"></span></span>');
                } else {
                    B.after('<span class="mbsc-segmented-item"><span class="mbsc-segmented-content mbsc-stepper-val"></span></span>');
                }
            }
            f.val(e).attr('data-role', 'stepper').attr('min', k).attr('max', j).attr('step', g).on('change', M);
            C = a('.mbsc-stepper-control', m).on('keydown', H).on('keyup', I).on('mousedown touchstart', J).on('touchmove', w).on('touchend touchcancel', v);
            f.addClass('mbsc-stepper-ready mbsc-control');
        };
        i.destroy = function() {
            f.removeClass('mbsc-control').off('change', M);
            C.off('keydown', H).off('keyup', I).off('mousedown touchstart', J).off('touchmove', w).off('touchend touchcancel', v);
            i._destroy();
        };
        i.init(y);
    };
    b.classes.Stepper.prototype = {
        _class: 'stepper',
        _defaults: {
            min: 0,
            max: 100,
            step: 1
        }
    };
    b.presetShort('stepper', 'Stepper');
    b.classes.Switch = function(f, e) {
        var d, g, h, c = this;
        e = e || {};
        a.extend(e, {
            changeEvent: 'click',
            min: 0,
            max: 1,
            step: 1,
            live: false,
            round: false,
            handle: false,
            highlight: false
        });
        b.classes.Slider.call(this, f, e, true);
        c._readValue = function() {
            return f.checked ? 1 : 0;
        };
        c._fillValue = function(a, c, b) {
            d.prop('checked', !!a);
            if (b) {
                d.trigger('change');
            }
        };
        c._onTap = function(a) {
            c._setVal(a ? 0 : 1);
        };
        c.__onInit = function() {
            h = c.settings;
            d = a(f);
            g = d.parent();
            g.find('.mbsc-switch-track').remove();
            g.prepend(d);
            d.attr('data-role', 'switch').after('<span class="mbsc-progress-cont mbsc-switch-track">' + '<span class="mbsc-progress-track mbsc-progress-anim">' + '<span class="mbsc-slider-handle-cont">' + '<span class="mbsc-slider-handle mbsc-switch-handle" data-index="0">' + '<span class="mbsc-switch-txt-off">' + h.offText + '</span>' + '<span class="mbsc-switch-txt-on">' + h.onText + '</span>' + '</span></span></span></span>');
            c._$track = g.find('.mbsc-progress-track');
        };
        c.getVal = function() {
            return f.checked;
        };
        c.setVal = function(a, b, d) {
            c._setVal(a ? 1 : 0, b, d);
        };
        c.init(e);
    };
    b.classes.Switch.prototype = {
        _class: 'switch',
        _css: 'mbsc-switch',
        _hasTheme: true,
        _hasLang: true,
        _defaults: {
            stopProp: true,
            offText: 'Off',
            onText: 'On'
        }
    };
    b.presetShort('switch', 'Switch');
    a(function() {
        a('[mbsc-enhance]').each(function() {
            a(this).mobiscroll().form();
        });
        a(document).on('mbsc-enhance', function(b, c) {
            if (a(b.target).is('[mbsc-enhance]')) {
                a(b.target).mobiscroll().form(c);
            } else {
                a('[mbsc-enhance]', b.target).each(function() {
                    a(this).mobiscroll().form(c);
                });
            }
        });
        a(document).on('mbsc-refresh', function(b) {
            if (a(b.target).is('[mbsc-enhance]')) {
                a(b.target).mobiscroll('refresh');
            } else {
                a('[mbsc-enhance]', b.target).each(function() {
                    a(this).mobiscroll('refresh');
                });
            }
        });
    });
}());

(function() {
    mobiscroll.themes.form['android-holo'] = {};
}());
(function() {
    mobiscroll.themes.form.ios = {};
}());
(function() {
    var a = mobiscroll.$;
    mobiscroll.themes.form.material = {
        onControlActivate: function(d) {
            var c, b = a(d.target);
            if (b[0].type == 'button' || b[0].type == 'submit') {
                c = b;
            }
            if (b.attr('data-role') == 'segmented') {
                c = b.next();
            }
            if (b.hasClass('mbsc-stepper-control') && !b.hasClass('mbsc-step-disabled')) {
                c = b.find('.mbsc-segmented-content');
            }
            if (c) {
                mobiscroll.themes.material.addRipple(c, d.domEvent);
            }
        },
        onControlDeactivate: function() {
            mobiscroll.themes.material.removeRipple();
        }
    };
}());
(function() {
    mobiscroll.themes.form.wp = {};
}());